package com.jl.magic.montage.slicer;

import com.jl.magic.montage.config.AbstractInlayConfig;
import com.jl.magic.montage.model.SubImage;

import java.awt.image.BufferedImage;
import java.util.List;

/**
 * @author jiangli
 * @create 2020/7/14 10:56 上午
 * 抽象的分割器
 */
public abstract class AbstractSlicer {

    /**
     * 源图
     */
    BufferedImage source;

    /**
     * image type
     *
     * @see BufferedImage#getType()
     */
    int type;

    /**
     * 图片高度
     */
    int height;

    /**
     * 图片宽度
     */
    int width;

    /**
     * 分割子图数量
     */
    int sliceCount;

    /**
     * 镶元图片配置
     */
    AbstractInlayConfig inlayConfig;

    public AbstractSlicer(BufferedImage source, AbstractInlayConfig inlayConfig, int sliceCount) {
        this.source = source;
        this.inlayConfig = inlayConfig;
        this.sliceCount = sliceCount;
    }

    public List<SubImage> divide() {

        type = source.getType();
        width = source.getWidth();
        height = source.getHeight();

        List<SubImage> subImages = doDivide();

        //clear by gc
        source = null;

        return subImages;
    }

    /**
     * 分割
     *
     * @return 子图列表
     */
    abstract List<SubImage> doDivide();
}
